from typing import Optional, List

from pydantic_settings import BaseSettings


class Settings(BaseSettings):
    # 应用配置
    app_name: str = "Disaster Recovery Service"
    app_version: str = "1.0.0"
    debug: bool = False
    host: str = "0.0.0.0"
    port: int = 8000

    # 数据库配置
    database_url: str = "mysql+pymysql://root:123456@localhost:3306/disaster_recovery?charset=utf8mb4"
    db_user: str = "root"
    db_password: str = "123456"
    db_host: str = "localhost"
    db_port: int = 3306
    db_name: str = "disaster_recovery"
    db_echo_sql: bool = False

    # Redis配置 (用于Celery)
    redis_url: str = "redis://localhost:6379/0"

    # 健康检查配置
    default_check_interval: int = 30  # 秒
    default_timeout: int = 10  # 秒
    default_retry_count: int = 3

    # 邮件配置
    smtp_server: Optional[str] = None
    smtp_port: int = 587
    smtp_username: Optional[str] = None
    smtp_password: Optional[str] = None
    smtp_use_tls: bool = True
    from_email: Optional[str] = None

    # 通知配置
    notification_enabled: bool = False
    webhook_urls: List[str] = []

    # 日志配置
    log_level: str = "INFO"
    log_file: Optional[str] = None
    log_max_size: int = 100 * 1024 * 1024  # 100MB
    log_backup_count: int = 5

    # 安全配置
    secret_key: str = "your-secret-key-change-this"
    access_token_expire_minutes: int = 30

    # Celery配置
    celery_broker_url: str = "redis://localhost:6379/0"
    celery_result_backend: str = "redis://localhost:6379/0"

    # 监控配置
    prometheus_enabled: bool = True
    prometheus_port: int = 8001

    class Config:
        env_file = ".env"
        case_sensitive = False


# 全局配置实例
settings = Settings()